﻿using System;
using System.Collections.Generic;
using System.Text;
using NFinal;

namespace NFinalCorePlugTest
{
    public class BaseTableController<TKey,TModel> : BaseController where TModel : class
    {
        public int pageSize=5;
        public ActionResult Insert()
        {
            TKey id = this.Insert<TKey, TModel>();
            return Json(id);
        }
        public ActionResult Update()
        {
            bool success= this.Update<TModel>();
            return Json(success);
        }
        public ActionResult Delete()
        {
            bool success= this.Delete<TModel>();
            return Json(success);
        }
        public ActionResult Page(int pageIndex)
        {
            IEnumerable<TModel> modelList= this.Page<TModel>(pageIndex, this.pageSize, out int cout);
            this.ViewBag = modelList;
            return Json();
        }
        public ActionResult Get()
        {
            TModel model = this.Get<TModel>();
            this.ViewBag = model;
            return Json();
        }
        public ActionResult GetAll()
        {
            IEnumerable<TModel> modelList = this.GetAll<TModel>(null);
            this.ViewBag = modelList;
            return Json();
        }
    }
}
